<?php

namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Model\UserLoginManager;

use App\Common\Common as common;


class ManagerController extends Controller {
//    添加商户登录密码
    public function addUser(){
        $request = $this->param;
        $validatorRule = ['merchantId','loginName','loginPasswd'];
        
        $flag = common::validateRequestField($request,$validatorRule);
        if( $flag !== true ) common::error(0,$flag);
        $insertData = [ 
            'merchantId'=>$request['merchantId'],
            'loginName'=>$request['loginName'],
            'loginPasswd'=>md5( $request['loginPasswd'] . env('APP_KEY') )
        ];
        
        UserLoginManager::insertGetId( $insertData );
        return common::success("添加会员登录成功了");
    }
//    修改商户登录信息（昵称、头像id)
    public function editUserInfo(){
        $request = $this->param;
        $validatorRule = ['merchantId','id'];
        $flag = common::validateRequestField( $request,$validatorRule );
        if( $flag !== true ) common::error(0,$flag);
        
        if( array_key_exists('imgSrc',$request) ){
            $request['loginShowId'] = common::getUploadPhoteFileId();
        }
        if( !array_key_exists('loginShowId',$request) && !array_key_exists('nickName', $request)){
            common::error(0,'传参参数错误');
        }
        $data = $where = [];
        if(array_key_exists('loginShowId', $request) )
            $data['loginShowId'] = $request['loginShowId'];
        if(array_key_exists('nickName', $request))
            $data['nickName'] = $request['nickName'];    
        $where['merchantId'] = $request['merchantId'];
        $where['id'] = $request['id'];
//        dump( $data );exit;
        UserLoginManager::where( $where )->update( $data );
        common::success('修改信息成功');
    }
}
